/* Copyright Sensoray Company Inc. 2007-2008
 * 2250/2251 SDK functions
 * Version 1.20.0
 * libs2250mid.a was compiled in 32 bit mode with gcc 323
 * It should be compatible with all 
 *
 */

#ifndef SRAY2250MID_H_
#define SRAY2250MID_H_

#include <sys/time.h>

#ifdef __cplusplus
extern "C"
{
#endif

#define DLLCP

/* maximum number of boards supported by SDK
 * Note: (The practical maximum number
 *        of boards may be less due to USB bandwidth
 *        constraints)
 */

#define MAX_BOARDS 32

// error constants 
#define MIDSRAY_SUCCESS             0
#define MIDSRAY_ERR_NONE            0

/* other errcodes standard Linux err codes 
 *  from errno.h or errno-base.h.  EG -ENODEV, -EINVAL, etc... 
 * MIDSRAY_ERR_NODEVICE changed to -ENODEV September 2008 release
 * MIDSRAY_ERR_NONEWDATA changed to -EAGAIN Sept 2008.
 * MIDSRAY_ERR_CAPTURING changed to -EBUSY Sept 2008
 * MIDSRAY_ERR_RUNNING changed to -EBUSY Sept 2008
 * MIDSRAY_ERR_NOTCAPTURING changed to -EFAULT Sept 2008
 */



/** video systems.  PAL or NTSC
 */
typedef enum
{
	MIDSRAY_VIDSYS_PAL=1,
	MIDSRAY_VIDSYS_NTSC=2
} MIDSRAY_VIDSYS;


typedef enum
{
	MIDSRAY_ENCODE_MPEG1 = 0,
	MIDSRAY_ENCODE_MPEG2 = 1,
	MIDSRAY_ENCODE_MPEG4 = 2,  // MP4S(not for VES)
	MIDSRAY_ENCODE_MOTIONJPEG = 3,
	MIDSRAY_ENCODE_MPEG4DIVX = 9, //(MPEG4 for VES)
} MIDSRAY_ENCODING;

/* for SN_GetOneFrame */
typedef struct
{
    int data_length;
    int type; //0 Iframe, 1 P frame, 2 Bframe
    struct timeval timestamp;
} frame_info_t;

/* detect number of boards plugged in */
DLLCP int SN_EnumBoards(void);

/* open 2250 board */
DLLCP int SN_OpenBoard( int boardnum);
/* close 2250 board */
DLLCP int SN_CloseBoard( int boardnum);

/* set the basic chip settings
 * Note: settings are not updated until stream started
 * (ie. if board running, must stop and restart to take effect).
 * video system and iVidSize determine the video size.  
 * @param boardnum board number
 * @param encodetype (see MIDSRAY_ENCODING)
 * @param iVidSize iVidSize == 0(full size), iVidSize ==1 (half size)
 * @param vsys video system
 * @param bitrate desired bitrate (default 2Mbit/s).
 * For iVidSize=1(half size), max bitrate is 2MBit/s.
 *  @param bIFramesOnly (default off=0).  To use IFrames only in the stream.
 */

DLLCP int SN_SetBasicChipSettings( int boardnum, MIDSRAY_ENCODING encodetype, int iVidSize, MIDSRAY_VIDSYS vsys, int bitrate, int bIFramesOnly );


/* start video and audio streams */
DLLCP int SN_StartStream(int boardnum);
/* stop streams */
DLLCP int SN_StopStream(int boardnum);

/* get one frame of video data in pBuf.  
 * BufLen specified in BufLen. size of frame returns in pFI->data_length
 */
DLLCP int SN_GetOneFrame(int boardnum, unsigned char *pBuf, int BufLen, frame_info_t *pFI);

/* get audio samples in pBuf.  Set buffer size in BufLen.
 *  Returns number of samples in BufLen
 */
DLLCP int SN_GetAudioData( int boardnum, unsigned char *pBuf, int *BufLen);

/* same as above, but returns a timestamp with the data
 * (Note: timestamp is best effort.  accuracy is not specified.)
 */
DLLCP int SN_GetAudioDataPlusTime( int boardnum, unsigned char *pBuf, int *BufLen, int *tv_sec, int *tv_usec);

/* set the video source 0 -- svideo, 1 -- composite(2250 only)
 */
DLLCP int SN_SetVideoSource( int boardnum, int source);

/* set video system.  0--NTSC, 1 PAL */
DLLCP int SN_SetVideoSystem( int boardnum, MIDSRAY_VIDSYS vidsys);

/* levels bright 0-100 (default 50) */
DLLCP int SN_SetBrightness( int boardnum, int bright);
/* contrast 0-100 (default 50) */
DLLCP int SN_SetContrast( int boardnum, int contrast);
/* hue -50 to 50 (default 0) */
DLLCP int SN_SetHue( int boardnum, int hue);
/* saturation 0-100 ( default 50) */
DLLCP int SN_SetSaturation( int boardnum, int sat);
/* set caption text */
DLLCP int SN_SetCaption( int boardnum, int xstart, int ystart, char *text);
/* clear caption text */
DLLCP int SN_ClearCaption( int boardnum);
/* source = 0(default line), source=1(mic), source =2 (mic with boost) */
DLLCP int SN_SetAudioSource( int boardnum, int source);

DLLCP int SN_SetHeight( int boardnum, int height);
DLLCP int SN_GetHeight( int boardnum, int *height);

DLLCP int SN_SetWidth( int boardnum, int w);
DLLCP int SN_GetWidth( int boardnum, int *w);

DLLCP int SN_SetBitrate( int boardnum, int bitrate);
DLLCP int SN_GetBitrate( int boardnum, int *bitrate);

/* advanced use only. see PDF manual */
DLLCP int SN_SetGopSize( int boardnum, int size);
DLLCP int SN_GetGopSize( int boardnum, int *size);
/* advanced use only. see PDF manual */
DLLCP int SN_SetSeqMode( int boardnum, int seqmode);
DLLCP int SN_GetSeqMode( int boardnum, int *seqmode);

/* returns current encoding type */
DLLCP int SN_GetEncodeType( int boardnum, MIDSRAY_ENCODING *encode);

/* set data retrieval to blocking (1s timeout) */
DLLCP int SN_SetBlocking(int boardnum);
/* set data retrieval to polling(immediate return even if no data */
DLLCP int SN_SetPolling(int boardnum);

/* sets global printf flag in the SDK. Loud output. for debug only */
DLLCP int SN_Debug(int bOnOff);


#ifdef __cplusplus
}
#endif

#endif


